package cn.zifangsky.jvm.part1.structure.onstackalloc;

/**
 * 栈上分配示例
 *
 * @author zifangsky
 * @date 2020/7/2
 * @since 1.0.0
 */
public class OnStackAllocation {

    /**
     * VM参数：
     * -Xmx10m -Xms10m -XX:+UseSerialGC -XX:+DoEscapeAnalysis -XX:-UseTLAB -XX:+EliminateAllocations -XX:+PrintGCDetails -verbose:gc
     * -Xmx10m -Xms10m -XX:+UseSerialGC -XX:+DoEscapeAnalysis -XX:-UseTLAB -XX:+PrintGCDetails -verbose:gc
     */
    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        for (int i = 0; i < 100000000; i++) {
            alloc();
        }

        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }

    public static void alloc() {
        User u = new User();
        u.id = 5;
        u.name = "coder";
    }

    public static class User {
        public int id = 0;
        public String name = "";
    }
}
